package com.attendance.service.impl;

import com.attendance.entity.User;
import com.attendance.mapper.UserMapper;
import com.attendance.service.UserService;
import jakarta.annotation.Resource;
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
import org.springframework.security.crypto.password.PasswordEncoder;
import org.springframework.stereotype.Service;

@Service
public class UserServiceImpl implements UserService {


    @Resource
    private UserMapper mapper;

    @Override
    public void saveUserDetails(User user) {
        PasswordEncoder encoder = new BCryptPasswordEncoder();
        user.setPassword(encoder.encode(user.getPassword()));
        mapper.insert(user);
    }

    @Override
    public User selectOneByEmail(String email) {
        return mapper.selectOneByEmail(email);
    }

    @Override
    public User searchInfoByEmail(String email) {
        return mapper.searchInfoByEmail(email);
    }

    @Override
    public int renameByEmail(String email, String newName) {
        return mapper.renameByEmail(email, newName);
    }

    @Override
    public User selectOneById(Integer user_id) {
        return mapper.selectOneById(user_id);
    }
}
